//
//  LeftLineView.m
//  JiaoX
//
//  Created by yinqy on 15/1/8.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "LeftLineView.h"
@interface LeftLineView()
{
    UIFont *_font;

    UIImageView *_image;
}
@end
@implementation LeftLineView

- (instancetype)initWithTitleFontSize:(CGFloat)fontSize
{
    self = [super init];
    if (self) {
        _font = [UIFont systemFontOfSize:fontSize];
        UIImage *leftImage = [UIImage imageNamed:@"left_line"];
        _image = [[UIImageView alloc]initWithImage:leftImage];
        _image.frame = CGRectMake(0, 0, leftImage.size.width, fontSize);
        [self addSubview:_image];
        _label = [[UILabel alloc]init];
        _label.font = _font;
        _label.numberOfLines = 0;
        _label.x = CGRectGetMaxX(_image.frame)+JXPublicInset*0.5;
        _label.y = 0;
        [self addSubview:_label];
    }
    return self;
}

-(void)setText:(NSString *)text constrainedToSize:(CGSize)size{
    [_label setText:text];
    size = CGSizeMake(size.width-_image.width-5, size.height);
    CGSize strSize = [text sizeWithFont:_font constrainedToSize:size];
    _label.width =strSize.width;
    _label.height = strSize.height;
    [self setSize:CGSizeMake(strSize.width+_image.width+JXPublicInset, strSize.height)];
}

-(void)setText:(NSString *)text{
    [_label setText:text];
    CGSize strSize = [text sizeWithFont:_font];
    _label.width =strSize.width;
    _label.height = strSize.height;
    [self setSize:CGSizeMake(strSize.width+_image.width+JXPublicInset/2, strSize.height)];
}

-(void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    _image.height = [_font lineHeight];
}


@end
